package com.yn.module.spider.init.data;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yn.module.spider.pojo.DicSpider;
import com.yn.module.spider.service.DicSpiderService;
import com.yn.module.spider.utils.constant.Const;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 数据初始化启动加载到缓存中
 * @author: 叶甯
 * @create: 2022/8/1 10:04
 * @since: 1.0.0
 * @copyright (C), 2022, https://gitee.com/johnny .All rights reserved.
 */
@Component
public class DataInit {
    // key: type+"_"+ table_name
    public static Map<String, DicSpider> DIC_SPIDER = new HashMap<>();
    @Resource
    private DicSpiderService dicSpiderService;

    @PostConstruct
    public void init() {
        LambdaQueryWrapper<DicSpider> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DicSpider::getRs,1);
        List<DicSpider> spiderList = dicSpiderService.list(queryWrapper);
        for (DicSpider obj : spiderList) {
            DIC_SPIDER.put(obj.getType() + Const.DEFAULT_SPLIT + obj.getTbName(), obj);
        }
    }

}
